package com.cm.caseManagement.controller;

import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmSysMenu;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmSysMenuService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 菜单权限Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/sysMenu")
public class CmSysMenuController extends BaseController
{
    @Autowired
    private ICmSysMenuService cmSysMenuService;

    /**
     * 查询菜单权限列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmSysMenu cmSysMenu)
    {
        startPage();
        List<CmSysMenu> list = cmSysMenuService.selectCmSysMenuList(cmSysMenu);
        return getDataTable(list);
    }

    /**
     * 导出菜单权限列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:export')")
    @Log(title = "菜单权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmSysMenu cmSysMenu)
    {
        List<CmSysMenu> list = cmSysMenuService.selectCmSysMenuList(cmSysMenu);
        ExcelUtil<CmSysMenu> util = new ExcelUtil<CmSysMenu>(CmSysMenu.class);
        util.exportExcel(response, list, "菜单权限数据");
    }

    /**
     * 获取菜单权限详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmSysMenuService.selectCmSysMenuById(id));
    }

    /**
     * 新增菜单权限
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:add')")
    @Log(title = "菜单权限", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmSysMenu cmSysMenu)
    {
        return toAjax(cmSysMenuService.insertCmSysMenu(cmSysMenu));
    }

    /**
     * 修改菜单权限
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:edit')")
    @Log(title = "菜单权限", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmSysMenu cmSysMenu)
    {
        return toAjax(cmSysMenuService.updateCmSysMenu(cmSysMenu));
    }

    /**
     * 删除菜单权限
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:menu:remove')")
    @Log(title = "菜单权限", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmSysMenuService.deleteCmSysMenuByIds(ids));
    }
}
